<?php

class HiddenTextParser extends StringFormatter {

	var $CanShow;
	/**
	 * @var Context
	 */
	var $Context;

	function HiddenTextParser(&$Context, $CanShow=0) {
		$this->CanShow = $CanShow;
		$this->Context =& $Context;
	}

	function Parse($String, $Object, $FormatPurpose) {
		$sReturn = $String;

		if ($FormatPurpose == FORMAT_STRING_FOR_DISPLAY) { // This is what you type in the comment box
			if ($this->CanShow) {
				$Patterns = array('/\[hide\](.+?)\[\/hide\]/is');
				$Replacements = array(
				'<div class="slideContainer">'
				.'<a href="#" class="ShowHidden">'
				. $this->Context->Configuration['HIDDEN_TEXT_MARKER_SHOW'] . '</a>'
				.'<div class="SlideText">$1'
				.'<span class="HideHiddenLink"><a href="#" class="HideHidden">'
				. $this->Context->Configuration['HIDDEN_TEXT_MARKER_HIDE']
				. '</a></span></div></div>');
			} else {
				$Patterns = array('/\[hide\](?:.+?)\[\/hide\]/is');
				$Replacements = array($this->Context->GetDefinition('HiddenTextRemoved'));
			}

			$sReturn = preg_replace($Patterns, $Replacements, $sReturn);
		}
		return $sReturn;
	}
}